//
//  MainViewController.m
//  sina_OC
//
//  Created by 李叶夫 on 16/9/22.
//  Copyright © 2016年 李叶夫. All rights reserved.
//

#import "MainViewController.h"
#import "HomeViewController.h"
#import "MessageViewController.h"
#import "DiscoverViewController.h"
#import "ProfileViewController.h"

@interface MainViewController ()

@end

@implementation MainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self addChildViewController];
    
}

///  添加子控制器
- (void)addChildViewController {
    
    UINavigationController *homeNav = [[UINavigationController alloc] initWithRootViewController:[[HomeViewController alloc] init]];
    [self setupTabBarItemWithController:homeNav imageName:@"tabbar_home" title:@"主页"];
    
    UINavigationController *messageNav = [[UINavigationController alloc] initWithRootViewController:[MessageViewController new]];
    [self setupTabBarItemWithController:messageNav imageName:@"tabbar_message_center" title:@"消息"];
    
    UINavigationController *emptyNav = [[UINavigationController alloc] initWithRootViewController:[UIViewController new]];
    
    UINavigationController *disNav = [[UINavigationController alloc] initWithRootViewController:[DiscoverViewController new]];
    [self setupTabBarItemWithController:disNav imageName:@"tabbar_discover" title:@"发现"];
    
    UINavigationController *profileNav = [[UINavigationController alloc] initWithRootViewController:[ProfileViewController new]];
    [self setupTabBarItemWithController:profileNav imageName:@"tabbar_profile" title:@"我"];

    self.viewControllers = @[homeNav, messageNav, emptyNav, disNav, profileNav];
}

///  设置tabBar
- (void)setupTabBarItemWithController:(UIViewController *)viewController imageName:(NSString *)imageName title:(NSString *)title {
    
    viewController.tabBarItem.image = [[UIImage imageNamed:imageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    viewController.tabBarItem.selectedImage = [[UIImage imageNamed:[NSString stringWithFormat:@"%@_selected",imageName]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    viewController.title = title;
    [viewController.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor darkGrayColor]} forState:UIControlStateNormal];
    [viewController.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor orangeColor]} forState:UIControlStateSelected];

}



@end





















